package ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ScrollView;

import com.peng.auctionsystem.R;

import Widget.CustomToolBar;
import base.BaseActivity;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import entity.ForgetPwdEntity;
import manager.ApiRequestManager;
import manager.RxSubscriber;
import utils.ToastUtil;

/**
 * 忘记密码界面
 */
public class ForgetPswActivity extends BaseActivity implements CustomToolBar.OnToolBarClickListener {

    @Bind(R.id.custom_toolbar)
    CustomToolBar customToolbar;
    @Bind(R.id.email)
    AutoCompleteTextView email;
    @Bind(R.id.password)
    EditText password;
    @Bind(R.id.email_sign_in_button)
    Button emailSignInButton;
    @Bind(R.id.email_login_form)
    LinearLayout emailLoginForm;
    @Bind(R.id.login_form)
    ScrollView loginForm;

    @Override
    public int getLayoutId() {
        return R.layout.activity_forget_psw;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        initViews();
    }

    private void initViews() {
        customToolbar.findTextView(R.id.left_tv).setVisibility(View.GONE);
        customToolbar.findImageView(R.id.left_iv).setVisibility(View.VISIBLE);
        customToolbar.findTextView(R.id.right_tv_main).setVisibility(View.GONE);
        customToolbar.findTextView(R.id.right_tv_sub).setVisibility(View.GONE);
        customToolbar.findTextView(R.id.center_tv).setText("忘记密码");
        customToolbar.setOnCustomToolBarClickListener(this);
    }

    @OnClick(R.id.email_sign_in_button)
    public void onViewClicked() {
        String account = email.getText().toString();
        String pwd = password.getText().toString();
        if (account == null || account.equals("")) {
            ToastUtil.showShort("请输入账号");
            return;
        }
        if (pwd == null || pwd.equals("")) {
            ToastUtil.showShort("请输入密码");
            return;
        }

        mRxManager.add(ApiRequestManager.getInstance().forgetPwd(account, pwd)
                .subscribe(new RxSubscriber<ForgetPwdEntity>(this, "正在处理...", true, false) {
                    @Override
                    protected void _onNext(ForgetPwdEntity baseResult) {
                        ToastUtil.showShort("操作成功");
                        finish();
                    }

                    @Override
                    protected void _onError(String message) {
                        ToastUtil.showShort("操作失败");
                    }
                }));

    }

    @Override
    public void onTitleLeftClick(View view) {
        finish();
    }

    @Override
    public void onTitleCenterClick(View view) {

    }

    @Override
    public void onTitleRightClick(View view) {

    }

    @Override
    public void onTitleRightSubClick(View view) {

    }
}

